<!DOCTYPE html>
<#assign base=springMacroRequestContext.getContextUrl("")>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- jqGrid组件基础样式包-必要 -->
    <link rel="stylesheet" href="${base}/glrStatic/jqgrid/css/ui.jqgrid.css" />

    <!-- jqGrid主题包-非必要 -->
    <!-- 在jqgrid/css/css这个目录下还有其他的主题包，可以尝试更换看效果 -->
    <link rel="stylesheet" href="${base}/glrStatic/jqgrid/css/css/redmond/jquery-ui-1.8.16.custom.css" />

    <!-- jquery插件包-必要 -->
    <!-- 这个是所有jquery插件的基础，首先第一个引入 -->
    <script type="text/javascript" src="${base}/glrStatic/jqgrid/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="${base}/glrStatic/viewOutline/ajax.js"></script>
    <!-- jqGrid插件包-必要 -->
    <script type="text/javascript" src="${base}/glrStatic/jqgrid/js/jquery.jqGrid.src.js"></script>

    <!-- jqGrid插件的多语言包-非必要 -->
    <!-- 在jqgrid/js/i18n下还有其他的多语言包，可以尝试更换看效果 -->
    <script type="text/javascript" src="${base}/glrStatic/jqgrid/js/i18n/grid.locale-cn.js"></script>
    <title>http://blog.mn886.net/jqGrid</title>
    <style>
        tr.ui-state-highlight td, tr.selected-row td{background: #dff0d8;}
    </style>
</head>
<body>
<div class="page-content container">
    <div class="page-body"> <!-- page-body -->
        <div class="panel panel-default" id="panel-orders">
            <table id="orders" class="table-bordered ly-jqgrid"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    var data = [], rowIds = [];
    function getBills() {
        var gatewayCode=getUrlParam("gatewayCode");
        var lightCode=getUrlParam("lightCode");
        var lightId=getUrlParam("lightId");
        var requestBody = {
            gatewayCode : gatewayCode,
            lightCode : lightCode,
            lightId:lightId
        };
        ajax.postRequest(requestBody, "gatawayPatternDatagrid", function(message) {
            var result=message.result;
            var rowCount = result.length;
            for (var i = 0; i < rowCount; i ++) {
                var pattern_name=result[i].pattern_name;
                var command_timea=result[i].command_timea;
                var bright_valuea=result[i].bright_valuea;
                var command_timeb=result[i].command_timeb;
                var bright_valueb=result[i].bright_valueb;
                var command_timec=result[i].command_timec;
                var bright_valuec=result[i].bright_valuec;
                var command_timed=result[i].command_timed;
                var bright_valued=result[i].bright_valued;
                var command_timee=result[i].command_timee;
                var bright_valuee=result[i].bright_valuee;
                data.push({
                    pattern_name: pattern_name,
                    command_timea: command_timea,
                    bright_valuea: bright_valuea,
                    command_timeb: command_timeb,
                    bright_valueb: bright_valueb,
                    command_timec: command_timec,
                    bright_valuec: bright_valuec,
                    command_timed: command_timed,
                    bright_valued: bright_valued,
                    command_timee: command_timee,
                    bright_valuee: bright_valuee,
                })
            }
            $("#orders").jqGrid("clearGridData").jqGrid('setGridParam',{data: data || []}).trigger('reloadGrid');


        }, function(message) {

        });
    }

    function page_resize() {
        var _height = $(window).height();
        $(".page-feature .page-content").outerHeight(_height);
        $(".ly-jqgrid").each(function(i, e){
            var $this = $(e), jobj = $this, jobj_parents = jobj.parents(".ui-jqgrid"), _h = 0;
            _h = _height - jobj.offset().top -  10;	// grid有效高度 = 总高度 - 表格高度起始位置 - 底部边距10
            _h = _h - (jobj_parents.find(".ui-jqgrid-pager").outerHeight() || 0) - (jobj_parents.find(".ui-jqgrid-ftable").outerHeight() || 0);
            if(_h > 0) {
                $this.jqGrid('setGridHeight', _h);
            }
        });
    }

    $(function() {
        $("#orders").jqGrid({
            colModel: [
                {label: "模式名称", name: "pattern_name", width: 180},
                {label: "时间a", name: "command_timea", width: 80},
                {label: "亮度a", name: "bright_valuea", width: 60},
                {label: "时间b", name: "command_timeb", width: 80},
                {label: "亮度b", name: "bright_valueb", width: 60 },
                {label: "时间c", name: "command_timec", width: 80},
                {label: "亮度c", name: "bright_valuec", width: 60 },
                {label: "时间d", name: "command_timed", width: 80},
                {label: "亮度d", name: "bright_valued", width: 60 },
                {label: "时间e", name: "command_timee", width: 80},
                {label: "亮度e", name: "bright_valuee", width: 60 },

            ],
            datatype: 'local',
            rownumbers: true,
            height: 300,
            multiselect: true,
        });
        getBills();
        $(window).on("load",function(){
            page_resize();
            $(window).resize(function(){
                setTimeout("page_resize()", 10);
            });
        });
    });

    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }
</script>
</body>
</html>
